package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.constant.ConstDictType;
import com.hee.erp.modules.entity.BusCustomerContact;
import com.hee.erp.modules.entity.SysDictValue;
import com.hee.erp.modules.mapper.BusCustomerContactMapper;
import com.hee.erp.modules.service.IBusCustomerContactService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hee.erp.modules.service.ISysDictValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-04-16
 */
@Service
@Transactional
public class BusCustomerContactServiceImpl extends ServiceImpl<BusCustomerContactMapper, BusCustomerContact> implements IBusCustomerContactService {

    @Autowired
    ISysDictValueService dictValueService;
    @Override
    public List<BusCustomerContact> getListByCustomerId(String customerId) {
        LambdaQueryWrapper<BusCustomerContact> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusCustomerContact::getCustomerId,customerId);
        List<BusCustomerContact> list = this.list(queryWrapper);
        for (BusCustomerContact contact : list) {
            //设置性别
            if(contact.getContactSex() != null){
                SysDictValue dictValue = dictValueService.getByTypeAndValue(ConstDictType.SEX, contact.getContactSex());
                contact.setContactSexName(dictValue.getDictName());
            }
        }
        return list;
    }

    @Override
    public List<String> listCustomerIdByLikeName(String managerOrContactor) {

        LambdaQueryWrapper<BusCustomerContact> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(BusCustomerContact::getContactName,managerOrContactor);
        List<BusCustomerContact> list = this.list(queryWrapper);
        List<String> customerIds = list.stream().map(BusCustomerContact::getCustomerId).distinct().collect(java.util.stream.Collectors.toList());
        return customerIds;

    }
}
